package cn.dengta.webapp.user.model;

import cn.dengta.common.model.ValueProxy;
import cn.dengta.common.model.ValueProxyImpl;
import lombok.Getter;
import me.codeplayer.util.Cmp;

@Getter
public enum GameBirdGoldLevel implements ValueProxyImpl<GameBirdGoldLevel, Integer> {
	L1(1, "GameBirdCoinLevel1", 0, 100, 200),
	L2(2, "GameBirdCoinLevel2", 101, 500, 300),
	L3(3, "GameBirdCoinLevel3", 501, 1000, 500),
	L4(4, "GameBirdCoinLevel4", 1001, Integer.MAX_VALUE, 600),
	;
	private final Integer value;
	public final String label;
	public final Integer minScore;
	public final Integer maxScore;
	public Integer golds;
	final ValueProxy<GameBirdGoldLevel, Integer> proxy;

	GameBirdGoldLevel(Integer value, String label, Integer minScore, Integer maxScore, Integer golds) {
		this.value = value;
		this.label = label;
		this.minScore = minScore;
		this.maxScore = maxScore;
		this.golds = golds;
		this.proxy = new ValueProxy<>(this, value, label);
	}

	public static GameBirdGoldLevel ofLabel(String label) {
		GameBirdGoldLevel[] values = GameBirdGoldLevel.values();
		for (GameBirdGoldLevel level : values) {
			if (level.getLabel().equals(label)) {
				return level;
			}
		}
		return null;
	}

	public static GameBirdGoldLevel ofScore(Integer score) {
		GameBirdGoldLevel[] values = GameBirdGoldLevel.values();
		for (GameBirdGoldLevel level : values) {
			boolean check = Cmp.ge(score, level.getMinScore()) && Cmp.le(score, level.getMaxScore());
			if (check) {
				return level;
			}
		}
		return null;
	}
}
